#include "HalfEdge.h"
#include <iostream>
#include <string>

int main()
{
	bool useDefault = false;
	auto input = [useDefault](Coord def, const std::string& info) mutable
	{
		Coord coord = def;
		if (useDefault) return coord;
		std::cout << "This is " << info << std::endl
			<< "The default value is : " << def.x << ' ' << def.y << ' ' << def.z << std::endl
			<< "[c] to input 3 float." << std::endl
			<< "[d] to accept the default value." << std::endl
			<< "[a] to use default value for all left values." << std::endl;
		char ch;
		std::cin >> ch;
		switch (ch) {
		case 'c':
			std::cin >> coord.x;
			std::cin >> coord.y;
			std::cin >> coord.z;
			break;
		case 'd':
			break;
		case 'a':
			useDefault = true;
			break;
		default:
			std::cout << "error" << std::endl;
			system("pause");
			std::terminate();
			break;
		}
		return coord;
	};
	auto ret0 = MakeVertexFaceSolid( input(Coord { 0.f, 0.f, 0.f }, "the first vertex") );
	auto loop = std::get<2>(ret0)->faces.front()->outerLoop;
	auto ret1 = MakeEdgeVertex(std::get<0>(ret0), loop, input(Coord { 5.f, 0.f, 0.f }, "the second vertex"));
	auto ret2 = MakeEdgeVertex(std::get<1>(ret1), loop, input(Coord { 5.f, 0.f, 3.f }, "the third vertex"));
	auto ret3 = MakeEdgeVertex(std::get<1>(ret2), loop, input(Coord { 0.f, 0.f, 3.f }, "the fourth vertex"));
	auto ret4 = MakeEdgeFace(loop, std::get<1>(ret3), std::get<0>(ret0));

	loop = std::get<1>(ret4)->outerLoop;
	auto ret5 = MakeEdgeVertex(std::get<0>(ret0), loop, input(Coord { 1.f, 0.f, 1.f }, "the fifth vertex"));
	auto ret6 = KillEdgeMakeRing(std::get<0>(ret0), std::get<1>(ret5), loop);
	
	loop = std::get<0>(ret6);
	auto ret7 = MakeEdgeVertex(std::get<1>(ret5), loop, input(Coord{ 2.f, 0.f, 1.f }, "the sixth vertex"));
	auto ret8 = MakeEdgeVertex(std::get<1>(ret7), loop, input(Coord{ 2.f, 0.f, 2.f }, "the seventh vertex"));
	auto ret9 = MakeEdgeVertex(std::get<1>(ret8), loop, input(Coord{ 1.f, 0.f, 2.f }, "the eighth vertex"));
	auto ret10 = MakeEdgeFace(loop, std::get<1>(ret9), std::get<1>(ret5));

	loop = std::get<1>(ret4)->outerLoop;
	auto ret11 = MakeEdgeVertex(std::get<1>(ret1), loop, input(Coord{ 4.f, 0.f, 1.f }, "the ninth vertex"));
	auto ret12 = KillEdgeMakeRing(std::get<1>(ret1), std::get<1>(ret11), loop);

	loop = std::get<0>(ret12);
	auto ret13 = MakeEdgeVertex(std::get<1>(ret11), loop, input(Coord{ 4.f, 0.f, 2.f }, "the tenth vertex"));
	auto ret14 = MakeEdgeVertex(std::get<1>(ret13), loop, input(Coord{ 3.f, 0.f, 2.f }, "the eleventh vertex"));
	auto ret15 = MakeEdgeVertex(std::get<1>(ret14), loop, input(Coord{ 3.f, 0.f, 1.f }, "the twelfth vertex"));
	auto ret16 = MakeEdgeFace(loop, std::get<1>(ret15), std::get<1>(ret11));

	Sweep(std::get<1>(ret4), input(Coord{ 0.f, 1.f, 0.f }, "the sweep direction"));
	KillFaceMakeRingHole(std::get<2>(ret0)->faces.front()->outerLoop, std::get<1>(ret10)->outerLoop);
	KillFaceMakeRingHole(std::get<2>(ret0)->faces.front()->outerLoop, std::get<1>(ret16)->outerLoop);
	Print(std::get<2>(ret0), "out.brp");
}